package com.ok.cartoon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ok.cartoon.domain.po.OkArea;
import com.ok.cartoon.domain.po.OkCartoon;
import com.ok.cartoon.mapper.OkAreaMapper;
import com.ok.cartoon.service.IOkAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ok.cartoon.service.IOkCartoonService;
import com.ok.common.exception.CustomException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 漫画地区 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-04-28
 */
@Service
@RequiredArgsConstructor
public class OkAreaServiceImpl extends ServiceImpl<OkAreaMapper, OkArea> implements IOkAreaService {

    private final IOkCartoonService okCartoonService;
    @Override
    public void removeWith(Integer id) {
        LambdaQueryWrapper<OkCartoon> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OkCartoon::getAreaId,id);
        int count = okCartoonService.count(queryWrapper);

        if (count != 0){
            throw new CustomException("该地区id下关联漫画，不能删除!");
        }

        this.removeById(id);
    }
}
